home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-08-16 | 3.0 KB | 86 lines | [TEXT/MPS ] |
- #----------------------------------------------------------------------------------------------------------------------------------------------------
- # SearchAll
- # MPW Shell Script
- # Written by Gina Cherry • August 16, 1991
- # Copyright: © 1991 by Apple Computer, Inc., all rights reserved.
- #
- # Usage:
- # SearchAll pattern [pathName…][-b][-i|-s][-nf][-ns][-sf][-q][-r][-f file]
- #
- # Function:
- # SearchAll will search for a given pattern in all files specified in pathName. The pattern can
- # be a string or a regular expression. If pathName is a directory, SearchAll will search all files
- # in that directory recursively. If no path name is specified, SearchAll will search the current
- # directory. The options for SearchAll are the same as the options for the MPW tool Search
- # (see the MPW Command Reference for more information).
- #
- #
- # Note:
- # The pattern must appear before the path name on the command line.
- #----------------------------------------------------------------------------------------------------------------------------------------------------
-
- # Don't exit on error.
- Set Exit 0
-
- # Initialize variables.
- # Pattern to search for.
- Set Pattern ""
- # List of pathnames to search.
- Set pathName ""
- # List of options to pass to Search command.
- Set Options ""
-
- # Loop through parameters.
- Loop
- # Break if no more parameters.
- Break If "{1}" == ""
- # If parameter is an option, add to list of options.
- If "{1}" == '-f'
- Set Options "{Options} {1}"
- Shift 1
- If "{1}"
- Set Options "{Options} {1}"
- End
- Else If "{1}" =~ /∂-[bisqr]/ || "{1}" =~ /∂-n[fs]/ || "{1}" =~ /∂-sf/
- Set Options "{Options} {1}"
- Else If "{1}" =~ /∂-≈/
- Echo "### {0}: ∂"{1}∂" is not an option."
- Echo "### Usage: {0} pattern [pathName…][-b][-i|-s][-nf][-ns][-sf][-q][-r][-f file]"
- Exit 1
- # If no pattern has been specified, set the pattern to the current parameter.
- Else If "{Pattern}" == ""
- Set Pattern "{1}"
- # Otherwise, add the parameter to the list of path names.
- Else
- Set pathName "{pathName} '{1}'"
- End
- # Get the next parameter.
- Shift 1
- End
-
- # If no pattern was specified, write error message and exit script.
- If "{Pattern}" == ""
- Echo "### {0}: No pattern to match."
- Echo "### Usage: {0} pattern [pathName…][-b][-i|-s][-nf][-ns][-sf][-q][-r][-f file]"
- Exit 1
- End >> Dev:StdErr
-
- # If no path name was specified, set pathName to the current directory.
- If "{pathName}" == ""
- Set pathName "`directory`"
- End
-
- # Loop through list of path names.
- For path in {pathName}
- # If the path name is valid, write progress info to standard output, and recursively search all
- # files and folders within the path.
- If "`Exists "{path}"`"
- Echo "# Searching ∂"{path}∂" for {Pattern}"
- Search "{Pattern}" `files -t TEXT -r -f "{path}"` {Options} ≥ Dev:Null
- Echo
- # Otherwise, write an error message and go on to next iteration of loop.
- Else
- Echo "### {0}: {path} is not a valid pathname.∂n" >> Dev:StdErr
- Continue
- End
- End